# Maintainer: Drew DeVault <sir@cmpwn.com>
pkgname=yggdrasil
pkgver=0.4.4
pkgrel=0
pkgdesc="An experiment in scalable routing as an encrypted IPv6 overlay network"
url="https://yggdrasil-network.github.io/"
arch="all"
license="LGPL-3.0-only"
makedepends="go"
install="$pkgname.post-install"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/yggdrasil-network/yggdrasil-go/archive/v$pkgver.tar.gz
	$pkgname.confd
	$pkgname.initd
	modules.conf
"
builddir="$srcdir/$pkgname-go-$pkgver"
options="!check" # upstream test suite is broken/unusual
subpackages="$pkgname-openrc"

build() {
	go mod vendor
	pkgsrc=github.com/yggdrasil-network/yggdrasil-go/src/version
	ldflags="-X $pkgsrc.buildName=$pkgname -X $pkgsrc.buildVersion=$pkgver"
	for cmd in yggdrasil yggdrasilctl
	do
		go build \
			-trimpath \
			-mod=vendor \
			-ldflags "-extldflags \"$LDFLAGS\" $ldflags" \
			./cmd/$cmd
	done
}

package() {
	install -Dm755 yggdrasil "$pkgdir"/usr/bin/yggdrasil
	install -Dm755 yggdrasilctl "$pkgdir"/usr/bin/yggdrasilctl
	install -Dm644 "$srcdir"/yggdrasil.confd \
		"$pkgdir"/etc/conf.d/yggdrasil
	install -Dm755 "$srcdir"/yggdrasil.initd \
		"$pkgdir"/etc/init.d/yggdrasil
	install -Dm644 "$srcdir"/modules.conf \
		"$pkgdir"/usr/lib/modules-load.d/yggdrasil.conf
}

sha512sums="
b61e5a22534d181ef48bde708c36eca83197a25e7e758dda7e81215e9e97db1a536f728fd4170784f6bdaf0742dbb1e3396fe71c06938272b0436cdb8665c0e0  yggdrasil-0.4.4.tar.gz
089221d9dd703b21714ac5ec04f23218083d216ff259fdd76942c9b2089ee4ca908b360dca0c1f4fa2e0bb1de7d57f0c638d8db9bc782cbe0ed1733f6888171a  yggdrasil.confd
3a65df7945389d91bcd43b75e2cab6d0982ca83322bdc196f7efdb00effa652b9297286b7743b12eeb6bcb41835e8dfb2d42cdcb131dfa46f8399485c6d80d75  yggdrasil.initd
871b650ff982be061532b4c5fe4812f41e6e2c58fc69b24f8a745f9a43389da44e742a69b0467b3c3d9e2b031af0728e20f10fa4584695c4f5ac87768a1fd34e  modules.conf
"
